part of '../repository.dart';

const _kPurchasedSubscriptionInfoCancellationSurveyReasonKey = 'reason';
const _kPurchasedSubscriptionInfoCancellationSurveyCustomAnswerKey = 'custom_answer';

class _PurchasedSubscriptionInfoCancellationSurveyResultDto extends Equatable {
  const _PurchasedSubscriptionInfoCancellationSurveyResultDto._internal({
    required this.reasonDto,
    required this.customAnswer,
  });

  final _PurchasedSubscriptionInfoCancellationSurveyReasonDto reasonDto;
  final String? customAnswer;

  @override
  List<Object?> get props {
    return [
      reasonDto,
      customAnswer,
    ];
  }

  factory _PurchasedSubscriptionInfoCancellationSurveyResultDto.fromJson(
      Map<String, dynamic> json) {
    final reasonString = json[_kPurchasedSubscriptionInfoCancellationSurveyReasonKey] as String;
    final reasonDto =
        _PurchasedSubscriptionInfoCancellationSurveyReasonDto.fromString(reasonString);

    return _PurchasedSubscriptionInfoCancellationSurveyResultDto._internal(
      reasonDto: reasonDto,
      customAnswer: json[_kPurchasedSubscriptionInfoCancellationSurveyCustomAnswerKey],
    );
  }

  factory _PurchasedSubscriptionInfoCancellationSurveyResultDto.fromEntity(
      GooglePlayPurchasedSubscriptionInfoCancellationSurveyResult surveyResult) {
    final reasonDto =
        _PurchasedSubscriptionInfoCancellationSurveyReasonDto.fromEntity(surveyResult.reason);

    return _PurchasedSubscriptionInfoCancellationSurveyResultDto._internal(
      reasonDto: reasonDto,
      customAnswer: surveyResult.customAnswer,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      _kPurchasedSubscriptionInfoCancellationSurveyReasonKey: reasonDto.toString(),
      _kPurchasedSubscriptionInfoCancellationSurveyCustomAnswerKey: customAnswer,
    };
  }

  GooglePlayPurchasedSubscriptionInfoCancellationSurveyResult toEntity() {
    return GooglePlayPurchasedSubscriptionInfoCancellationSurveyResult(
      reason: reasonDto.toEntity(),
      customAnswer: customAnswer,
    );
  }
}
